import 'package:app/jspangStudy/widget/routeAnimate.dart';
import 'package:flutter/material.dart';

class ExpactNavBar extends StatefulWidget {
  ExpactNavBar({Key key}) : super(key: key);

  @override
  _ExpactNavBarState createState() => _ExpactNavBarState();
}

class _ExpactNavBarState extends State<ExpactNavBar> {
  List<Widget> views;
  int _index = 0;

  @override
  void initState() {
    views = List();
    views..add(ViewPage('home'))..add(ViewPage('email'));
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: views[_index],
      floatingActionButton: FloatingActionButton(
        // 不规则底部导航按钮
        onPressed: () {
          Navigator.of(context).push(
            // MaterialPageRoute(
            //   builder: (BuildContext context) {
            //     return ViewPage('newPage');
            //   },
            // ),
            RouterAnimate(ViewPage('newPage')), //路由跳转
          );
        },
        tooltip: '长按提示',
        child: Icon(
          Icons.add,
          color: Colors.white,
        ),
      ),
      floatingActionButtonLocation:
          FloatingActionButtonLocation.centerDocked, // 位置
      bottomNavigationBar: BottomAppBar(
        // 底部工具栏
        color: Colors.lightBlue,
        shape: CircularNotchedRectangle(), //圆形缺口
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          mainAxisSize: MainAxisSize.max,
          children: <Widget>[
            IconButton(
              icon: Icon(Icons.home),
              color: Colors.white,
              onPressed: () {
                setState(() {
                  _index = 0;
                });
              },
            ),
            IconButton(
              icon: Icon(Icons.email),
              color: Colors.white,
              onPressed: () {
                setState(() {
                  _index = 1;
                });
              },
            )
          ],
        ),
      ),
    );
  }
}

// ignore: must_be_immutable
class ViewPage extends StatefulWidget {
  String _title;
  ViewPage(this._title);
  @override
  _ViewPageState createState() => _ViewPageState();
}

class _ViewPageState extends State<ViewPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget._title),
      ),
      body: Center(
        child: Text(widget._title),
      ),
    );
  }
}
